
var config = require('../config');
var log = require('../lib/log');
var RUtil = require('./dataformatUtil');
var login = require('./login');
var crypto = require('crypto');

var notify=require('../models/notify.js');
exports.index = function(request, response){
    if(request.session.admin==undefined)
    {
        response.redirect("login.html");
    }
    else
    {
        var data = RUtil.indexdata(request);

        data.retdata.nickname =request.session.admin.nickname;
        data.retdata.lastlogindate =request.session.admin.lastlogindate;
        data.retdata.lastloginip =request.session.admin.lastloginip;
        data.retdata.roleinfo = request.session.roleinfo;
        data.retdata.userinfo = request.session.admin;
        data.retdata.title="控制台";

        notify.selectToUserID(request.session.admin.id, function(error,results) {
            if((error)!== null)
            {
                // 数据库异常
                //data.retdata.info = "载入失败：系统内部错误(错误码："+error.errno+")";
                data.retdata.success=false;
                response.render("index", data);

            }
            else if(results.length <= 0) {
                // 不存在，直接响应页面
                //data.retdata.info = "没有任何通知记录!";
                data.retdata.success=false;
                response.render("index", data);
            } else {


                //存在数据将数据发到页面
                //data.retdata.info = "通知提取成功!";
                data.retdata.success=true;
                data.notifys= results;

                response.render("index", data);
            }
        });

        //response.render('index', data);
    }
};





